// ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
/*============================================================
** 
** Class:  Comparer 
**
** 
** Purpose: Default IComparer implementation.
**
**
===========================================================*/ 
namespace System.Collections {
 
    using System; 
    using System.Globalization;
    using System.Runtime.Serialization; 
    using System.Security.Permissions;

   
    public sealed class Comparer : IComparer 
    { 
        private CompareInfo m_compareInfo; 
   

        private const String CompareInfoName = "CompareInfo";

        public Comparer() { 
            m_compareInfo = null;
        } 
 
    

    

        // Compares two Objects by calling CompareTo.  If a == 
        // b,0 is returned.  If a implements
        // IComparable, a.CompareTo(b) is returned.  If a
        // doesn't implement IComparable and b does,
        // -(b.CompareTo(a)) is returned, otherwise an 
        // exception is thrown.
        // 
        public int Compare(Object a, Object b) { 
            if (a == b) return 0;
            if (a == null) return -1; 
            if (b == null) return 1;
            if (m_compareInfo != null) {
                String sa = a as String;
                String sb = b as String; 
                if (sa != null && sb != null)
                    return m_compareInfo.Compare(sa, sb); 
            } 

            IComparable ia = a as IComparable; 
            if (ia != null)
                return ia.CompareTo(b);

            throw new ArgumentException(("Argument_ImplementIComparable")); 
        }
 
      
        
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
